package com.luxoft.scoremanager.server.model.bean;

import com.luxoft.scoremanager.server.model.entity.ComponentValue;
import com.luxoft.scoremanager.server.model.entity.ScorePackage;
import com.luxoft.scoremanager.server.model.entity.StaticData;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


public class ScorePackageBean implements Serializable {
    private static final long serialVersionUID = -5170875020617735654L;

    private Integer id;

    private String stage;

    private List<ComponentBean> components = new ArrayList<ComponentBean>();

    private List<StaticDataBean> staticDatas = new ArrayList<StaticDataBean>();

    public ScorePackageBean() {

    }

    public ScorePackageBean(ScorePackage scorePackage, List<StaticData> staticDataList) {
        this.setId(scorePackage.getId());
        this.setStage(scorePackage.getStage());
        for (ComponentValue componentValue : scorePackage.getComponentsValues()) {
            this.addComponent(new ComponentBean(componentValue));
        }
        for (StaticData staticData : staticDataList) {
            this.addStaticData(new StaticDataBean(staticData));
        }
    }

    public ScorePackageBean(String stage) {
        this.stage = stage;
    }

    @Deprecated
    public ScorePackageBean(Integer id, String stage) {
        this.id = id;
        this.stage = stage;
    }

    public List<StaticDataBean> getStaticDatas() {
        return staticDatas;
    }

    public void setStaticDatas(List<StaticDataBean> staticDataBean) {
        this.staticDatas = staticDataBean;
    }

    public void addStaticData(StaticDataBean staticDataBean) {
        this.staticDatas.add(staticDataBean);
    }

    public void removeStaticData(StaticDataBean staticDataBean) {
        if (this.staticDatas.contains(staticDataBean)) {
            this.staticDatas.remove(staticDataBean);
        }
    }

    public List<ComponentBean> getComponents() {
        return components;
    }

    public void setComponents(List<ComponentBean> components) {
        this.components = components;
    }

    public void addComponent(ComponentBean componentBean) {
        this.components.add(componentBean);
    }

    public void removeComponent(ComponentBean componentBean) {
        if (this.components.contains(componentBean)) {
            this.components.remove(componentBean);
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getStage() {
        return stage;
    }

    public void setStage(String stage) {
        this.stage = stage;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ScorePackageBean that = (ScorePackageBean) o;

        if (components != null ? !components.equals(that.components) : that.components != null) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (stage != null ? !stage.equals(that.stage) : that.stage != null) return false;
        if (staticDatas != null ? !staticDatas.equals(that.staticDatas) : that.staticDatas != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (stage != null ? stage.hashCode() : 0);
        result = 31 * result + (components != null ? components.hashCode() : 0);
        result = 31 * result + (staticDatas != null ? staticDatas.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Package{" +
                "id=" + id +
                ", stage='" + stage + '\'' +
                '}';
    }

}
